package com.yykj.im.center.server.controller;

import com.yykj.common.vo.ResultVO;
import com.yykj.im.center.client.dto.ClientSystemNoticeDto;
import com.yykj.im.center.client.dto.SystemNoticeDto;
import com.yykj.im.center.client.dto.base.PaginationListDto;
import com.yykj.im.center.client.form.base.BasePaginationForm;
import com.yykj.im.center.client.form.consultation.SystemNoticeConditionForm;
import com.yykj.im.center.client.form.consultation.SystemNoticeListForm;
import com.yykj.im.center.client.form.consultation.SystemNoticeSendAgainForm;
import com.yykj.im.center.client.form.consultation.SystemNoticeUpdateForm;
import com.yykj.im.center.server.service.BizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;


@RestController
@RequestMapping("/api/im")
@Api(tags = "业务IM")
public class BizController {

    @Autowired
    BizService bizService;

    @PostMapping("/system/notice/send")
    @ApiOperation(value = "按条件推送")
    public ResultVO systemNoticeSend(@RequestBody @Valid SystemNoticeConditionForm systemNoticeConditionForm) {
        bizService.systemNoticeCondition(systemNoticeConditionForm);
        return ResultVO.success();
    }

    @PostMapping("/system/notice/list")
    @ApiOperation(value = "通知列表")
    public ResultVO<PaginationListDto<SystemNoticeDto>> systemNoticeList(@RequestBody @Valid SystemNoticeListForm systemNoticeListForm) {
        return ResultVO.success(bizService.systemNoticeList(systemNoticeListForm));
    }

    @PostMapping("/system/notice/update")
    @ApiOperation(value = "修改通知")
    public ResultVO systemNoticeUpdate(@RequestBody @Valid SystemNoticeUpdateForm systemNoticeUpdateForm) {
        bizService.systemNoticeUpdate(systemNoticeUpdateForm);
        return ResultVO.success();
    }

    @ApiIgnore
    @PostMapping("/system/notice/sendAgain")
    @ApiOperation(value = "再次发送通知")
    public ResultVO systemNoticeSendAgain(@RequestBody @Valid SystemNoticeSendAgainForm systemNoticeSendAgainForm) {
        bizService.systemNoticeSendAgain(systemNoticeSendAgainForm);
        return ResultVO.success();
    }

    @ApiIgnore
    @GetMapping("/system/notice/delete/{id}")
    @ApiOperation(value = "删除通知")
    public ResultVO systemNoticeDelete(@PathVariable String id) {
        bizService.systemNoticeDelete(id);
        return ResultVO.success();
    }


    @PostMapping("/client/system/notice/list")
    @ApiOperation(value = "客户端通知列表")
    public ResultVO<PaginationListDto<ClientSystemNoticeDto>> clientSystemNoticeList(@RequestBody @Valid BasePaginationForm basePaginationForm) {
        return ResultVO.success(bizService.clientSystemNoticeList(basePaginationForm));
    }

}